﻿using System.Data;
using System.IO;
using Migrator.Framework;
using System;

/*
 * Use of command line tool
 * Migrator.Console.exe "SqlServer" "Server=localhost\SQLEXPRESS;initial catalog=wines;Integrated Security=SSPI" d:\OSS\WineCellarManagerASPNETMVC\WineCellar.Migrator\bin\Debug\WineCellar.Migrator.dll -version 2
 * 
 * http://code.google.com/p/migratordotnet/
 */

namespace WineCellar.Migrator
{    
    [Migration(1)]
    public class Migration001CreateSecuritySchema :Migration
    {
        public override void Up()
        {
            string sql;
            Console.Out.WriteLine(System.Environment.CurrentDirectory);
            using (StreamReader rdr = File.OpenText(@"..\..\Core\WineCellar.Migrator\schemaExport.sql"))
            {
                sql = rdr.ReadToEnd();
            }
            Database.ExecuteNonQuery(sql);
        }

        public override void Down()
        {
            Database.RemoveTable("[User]");
            Database.RemoveTable("security_EntitiesGroups");
            Database.RemoveTable("security_EntityReferences");
            Database.RemoveTable("security_EntityTypes");
            Database.RemoveTable("security_Operations");
            Database.RemoveTable("security_Permissions");
            Database.RemoveTable("security_UsersGroups");
            Database.RemoveTable("UsersToUsersGroups");
            Database.RemoveTable("UsersGroupsHierarchy");
        }
    }
}
